<!-- 资源库 -->
<template>
  <div>
    <mk-search-box>
      <el-row>
        <el-col :span="5">
          <label>资源名称:</label>
          <el-input v-model="ui.searchData.rsname"
                    size="small"></el-input>
        </el-col>
        <el-col :span="3">
          <mk-search-buttons v-model="ui.searching" />
        </el-col>
      </el-row>
    </mk-search-box>
    <el-row>
      <add @reload="doSearch"
           :rstype="rstype" />
    </el-row>
    <mk-table v-model="ui"
              mk-index
              mk-sql-code="cmResource.select_list"
              :mk-table-id="'cm-resource.list.common.'+rstype"
              :mk-init-search-data="initSearchData"
              ref="table">
      <el-table-column align="left"
                       v-if="rstype==='GOMEZ'"
                       prop="rsuri"
                       label="素材"
                       width="350" />
      <el-table-column align="left"
                       v-else
                       prop="rsname"
                       label="资源名称"
                       width="150" />
      <el-table-column align="left"
                       prop="isactive"
                       label="可见"
                       width="90">
        <template slot-scope="scope">
          {{scope.row.isactive | data-config('FLAG')}}
        </template>
      </el-table-column>
      <el-table-column align="left"
                       prop="createtime"
                       label="创建时间"
                       width="150">
      </el-table-column>
      <el-table-column align="left"
                       prop="realname"
                       label="创建人"
                       width="80">
      </el-table-column>
      <el-table-column prop="doing"
                       align="center"
                       label="操作"
                       width="120">
        <template slot-scope="scope">
          <edit :row="scope.row"
                :rstype="rstype"
                @reload="doSearch" />
          <mk-button :type="4"
                     confirm-text="确定要删除么？"
                     @click="deleteByid(scope.row)">删除</mk-button>
        </template>
      </el-table-column>
    </mk-table>
  </div>
</template>

<script>
  import { MkBase } from 'element-ui'
  import Add from './list/add-button'
  import Edit from './list/edit-button'
  import searchData from './list/search-data'

  export default {
    name: 'cm-resource-list',
    mixins: [MkBase],
    components: {
      Add,
      Edit
    },
    props: {
      rstype: String
    },
    data () {
      return {
        ui: {
          searching: true,
          searchData: searchData()
        }
      }
    },
    created () {
      this.ui.searchData.rstype = this.rstype
    },
    methods: {
      initSearchData (data, reset) {
        data.rstype = this.rstype
      },
      /**
       * 刷新本页面
       */
      doSearch () {
        this.ui.searching = true
      },

      async deleteByid (row) {
        let data = await this.$delete('cmResource/deleteByid.json', {
          rsid: row.rsid
        })
        if (data) {
          this.doSearch()
        }
      }
    }
  }
</script>
